package com.unionpay.mpds.web.action.menu;

import java.util.List;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.json.annotations.JSON;
import org.springframework.beans.factory.annotation.Autowired;

import com.unionpay.mpds.model.Menu;
import com.unionpay.mpds.service.MenuService;
import com.unionpay.mpds.web.action.BaseAction;

@ParentPackage("json-center")
public class MenuAction extends BaseAction {

	@Autowired
	private MenuService menuService;
	
	private Menu menu; //菜单对象
	private String sessionId;
	private List<Menu> menus;
	//private ReturnParams returnParams = new ReturnParams();
	
//	private String return_code = "0";
//	
//	private Map<String, Object> body = new HashMap<String , Object>();
//
//	private String return_info = "";
	
	@Action("menu")
	public String menu() throws Exception {
//		Map<String, Object> params = new HashMap<String, Object>();
//		params.put("menuStatus", "1");
//		menus = menuService.findByParam(Integer.MAX_VALUE, params);
		menus = menuService.getMenusByRole("888");
		return "menu";
	}

	@Action(value="menuAjax", results={@Result(name="menuIndex", type="json", params={"root", "returnParams"})})
	public String menuAjax() throws Exception {
		menus = menuService.getMenusByRole("888");
		returnParams.setDatas(menus);
		return "menuIndex";
	}
	
	//post方式提交
	@Action(value="menuPostDo", results={@Result(name="menu", location="../menu/menu.htm", type="redirect")})
	public String menuPostDo() throws Exception {
		if (null!=menu) {
			menuService.save(menu);
		}
		
		return "menu";
	}
	
	//ajax方式提交
	@Action(value="menuAjaxDo", results={@Result(name="success", type="json")})
	public String menuAjaxDo() throws Exception {
		if (null!=menu) {
			menuService.save(menu);
			getSession().put("sessionId", menu.getMenuId());
			sessionId = (String) getSession().get("sessionId");
			
		}
		return SUCCESS;
	}

	public Menu getMenu() {
		return menu;
	}

	public void setMenu(Menu menu) {
		this.menu = menu;
	}
	@JSON
	public String getSessionId() {
		return sessionId;
	}

	public void setSessionId(String sessionId) {
		this.sessionId = sessionId;
	}
	
	public List<Menu> getMenus() {
		return menus;
	}

	public void setMenus(List<Menu> menus) {
		this.menus = menus;
	}

//	public ReturnParams getReturnParams() {
//		return returnParams;
//	}
//
//	public void setReturnParams(ReturnParams returnParams) {
//		this.returnParams = returnParams;
//	}
	
}
